BX.namespace("BX.UI");if(typeof BX.UI.EntityValidator==="undefined"){BX.UI.EntityValidator=function(){this._settings={};this._editor=null;this._data=null};BX.UI.EntityValidator.prototype={initialize:function(t){this._settings=t?t:{};this._editor=BX.prop.get(this._settings,"editor",null);this._data=BX.prop.getObject(this._settings,"data",{});this.doInitialize()},doInitialize:function(){},release:function(){},getData:function(){return this._data},getDataStringParam:function(t,i){return BX.prop.getString(this._data,t,i)},getErrorMessage:function(){return BX.prop.getString(this._settings,"message","")},validate:function(t){return true},processControlChange:function(t){}}}if(typeof BX.UI.EntityPersonValidator==="undefined"){BX.UI.EntityPersonValidator=function(){BX.UI.EntityPersonValidator.superclass.constructor.apply(this)};BX.extend(BX.UI.EntityPersonValidator,BX.UI.EntityValidator);BX.UI.EntityPersonValidator.prototype.doInitialize=function(){this._nameField=this._editor.getControlById(this.getDataStringParam("nameField",""));if(this._nameField){this._nameField.addValidator(this)}this._lastNameField=this._editor.getControlById(this.getDataStringParam("lastNameField",""));if(this._lastNameField){this._lastNameField.addValidator(this)}};BX.UI.EntityPersonValidator.prototype.release=function(){if(this._nameField){this._nameField.removeValidator(this)}if(this._lastNameField){this._lastNameField.removeValidator(this)}};BX.UI.EntityPersonValidator.prototype.validate=function(t){var i=this._nameField.isActive();var e=this._lastNameField.isActive();if(!i&&!e){return true}var r=i?this._nameField.getRuntimeValue():this._nameField.getValue();var n=e?this._lastNameField.getRuntimeValue():this._lastNameField.getValue();if(r!==""||n!==""){return true}if(r===""&&i){t.addError(BX.UI.EntityValidationError.create({field:this._nameField}));this._nameField.showError(this.getErrorMessage())}if(n===""&&e){t.addError(BX.UI.EntityValidationError.create({field:this._lastNameField}));this._lastNameField.showError(this.getErrorMessage())}return false};BX.UI.EntityPersonValidator.prototype.processFieldChange=function(t){if(t!==this._nameField&&t!==this._lastNameField){return}if(this._nameField){this._nameField.clearError()}if(this._lastNameField){this._lastNameField.clearError()}};BX.UI.EntityPersonValidator.create=function(t){var i=new BX.UI.EntityPersonValidator;i.initialize(t);return i}}if(typeof BX.UI.EntityValidationError==="undefined"){BX.UI.EntityValidationError=function(){this._settings={};this._field=null;this._message=""};BX.UI.EntityValidationError.prototype={initialize:function(t){this._settings=t?t:{};this._field=BX.prop.get(this._settings,"field",null);this._message=BX.prop.getString(this._settings,"message","")},getField:function(){return this._field},getMessage:function(){return this._message}};BX.UI.EntityValidationError.create=function(t){var i=new BX.UI.EntityValidationError;i.initialize(t);return i}}if(typeof BX.UI.EntityValidationResult==="undefined"){BX.UI.EntityValidationResult=function(){this._settings={};this._errors=[]};BX.UI.EntityValidationResult.prototype={initialize:function(t){this._settings=t?t:{}},getStatus:function(){return this._errors.length===0},addError:function(t){this._errors.push(t)},getErrors:function(){return this._errors},addResult:function(t){var i=t.getErrors();for(var e=0,r=i.length;e<r;e++){this._errors.push(i[e])}},getTopmostField:function(){var t=null;var i=null;for(var e=0,r=this._errors.length;e<r;e++){var n=this._errors[e].getField();if(!t){t=n;i=n.getPosition()["top"];continue}var a=n.getPosition();if(!a){continue}var o=n.getPosition()["top"];if(o<i){t=n;i=o}}return t}};BX.UI.EntityValidationResult.create=function(t){var i=new BX.UI.EntityValidationResult;i.initialize(t);return i}}if(typeof BX.UI.EntityAsyncValidator==="undefined"){BX.UI.EntityAsyncValidator=function(){this.promisesList=[];this.isValid=true};BX.UI.EntityAsyncValidator.prototype={addResult:function(t){if(t instanceof Promise||t instanceof BX.Promise){this.promisesList.push(t)}else{this.isValid=this.isValid&&t}},validate:function(){if(this.promisesList.length){return Promise.all(this.promisesList)}return this.isValid}};BX.UI.EntityAsyncValidator.create=function(){return new BX.UI.EntityAsyncValidator}}if(typeof BX.UI.EntityTrackingSourceValidator==="undefined"){BX.UI.EntityTrackingSourceValidator=function(){BX.UI.EntityTrackingSourceValidator.superclass.constructor.apply(this)};BX.extend(BX.UI.EntityTrackingSourceValidator,BX.UI.EntityValidator);BX.UI.EntityTrackingSourceValidator.prototype.doInitialize=function(){this._trackingSourceField=this._editor.getControlById(this.getDataStringParam("fieldName",""));if(this._trackingSourceField){this._trackingSourceField.addValidator(this)}};BX.UI.EntityTrackingSourceValidator.prototype.release=function(){if(this._trackingSourceField){this._trackingSourceField.removeValidator(this)}};BX.UI.EntityTrackingSourceValidator.prototype.validate=function(t){var i=this._trackingSourceField.isActive();var e="";var r;if(!i||!(this._trackingSourceField.isRequired()||this._trackingSourceField.isRequiredByAttribute())){return true}if(i){if(this._trackingSourceField.hasOwnProperty("_innerWrapper")&&BX.Type.isDomNode(this._trackingSourceField["_innerWrapper"])){r=this._trackingSourceField["_innerWrapper"].querySelector("select[name="+this._trackingSourceField.getId().replace(/["\\]/g,"\\$&")+"]");if(r){e=r.value}}}else{e=this._trackingSourceField.getValue()}if(e!==""){return true}if(e===""&&i){t.addError(BX.UI.EntityValidationError.create({field:this._trackingSourceField}));this._trackingSourceField.showError(this._trackingSourceField.getMessage("requiredFieldError"))}return false};BX.UI.EntityTrackingSourceValidator.prototype.processFieldChange=function(t){if(t!==this._trackingSourceField){return}if(this._trackingSourceField){this._trackingSourceField.clearError()}};BX.UI.EntityTrackingSourceValidator.create=function(t){var i=new BX.UI.EntityTrackingSourceValidator;i.initialize(t);return i}}
//# sourceMappingURL=validator.map.js